package com.self.admin.controller;

import com.self.admin.model.SysMenu;
import com.self.admin.service.SysRolePrivilegeService;
import com.self.admin.vo.RolePrivilegesParamVo;
import com.self.common.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version v1.0
 * @ClassName: SysRolePrivilegeController
 * @Description:
 * @Author: Mac
 * @Date: 2022/6/4 17:28
 */
@Api(tags = "角色权限的配置")
@RestController
public class SysRolePrivilegeController {

    @Autowired
    private SysRolePrivilegeService sysRolePrivilegeService ;


    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    public R<List<SysMenu>> findSysMenuAndPrivileges(Long roleId){
        List<SysMenu> sysMenus  = sysRolePrivilegeService.findSysMenuAndPrivileges(roleId);
        return R.ok(sysMenus);
    }


    @PostMapping("/grant_privileges")
    @ApiOperation(value = "授予角色某种权限")
    public R grantPrivileges(@Validated @RequestBody RolePrivilegesParamVo rolePrivilegesParam){
       sysRolePrivilegeService.grantPrivileges(rolePrivilegesParam);
       return R.ok();
    }
}
